<template>
  <div class="box">
    <h2>Son2子组件</h2>
    从vuex中获取的值：<label>{{ $store.state.count }}</label>
    <br>
    <button @click="handleSub(1)">值 - 1</button>
    <button @click="handleSub(5)">值 - 5</button>
    <button @click="handleSub(10)">值 - 10</button>
    <button @click="handleChange">一秒后修改成666</button>
    <button @click="changeTitle">改标题</button>
    <hr>
    <div>{{ $store.state.list }}</div>
    <div>{{ $store.getters.filterList }}</div>
    <hr>
    <div>{{ $store.state.user.userInfo.name }}</div>
    <button @click="updateUser">更新个人信息</button>
    <button @click="updateUser2">一秒后更新信息</button>
    <div>{{ $store.state.setting.theme }}</div>
    <button @click="updateTheme">更新主题色</button>

    <hr>
    <div>{{ $store.getters['user/UpperCaseName'] }}</div>
  </div>
</template>

<script>
export default {
  name: 'Son2Com',
  methods: {
    updateUser () {
      this.$store.commit('user/setUser', {
        name: 'xiaowang',
        age: 88
      })
    },
    updateUser2 () {
    //  难点 调用action dispatch
      this.$store.commit('user/setUserSecond', {
        name: 'lililili',
        age: 888
      })
    },
    updateTheme () {
      this.$store.commit('setting/setTheme', 'red')
    },
    handleSub (n) {
      // this.$store.state.count--
      // console.log(this.$store.state.count)
      this.$store.commit('subCount', {
        count: n,
        msg: 'li'
      })
    },
    handleChange () {
      this.$store.dispatch('changeCountAsync', 666)
    },
    changeTitle () {
      this.$store.commit('changeTitle', '还有102集')
    }
  }
}
</script>

<style lang="css" scoped>
.box{
  border:3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2{
  margin-top:10px ;
}

</style>
